package com.mongodb.controller;

/**
 * @author ：qs
 * @date ：Created in 2022/9/5
 * @description：
 * @modified By：
 */
import com.mongodb.entity.Story;
import com.mongodb.service.StoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class StoryController {
    private StoryService storyService;

    @Autowired
    public void setStoryService(StoryService storyService) {
        this.storyService = storyService;
    }

    @PostMapping("/add/story")
    public boolean addStory(@RequestBody Story story){
        try{
            this.storyService.addStory(story);
            return true;
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }
    }
    @GetMapping("/get/stories")
    public String getStories(){
        return this.storyService.findAllStory().toString();
    }
    @GetMapping("/get/story/{id}")
    public String getStoryById(@PathVariable String id){
        return this.storyService.findStoryById(id).toString();
    }
    @GetMapping("/get/story/content")
    public String getContent(String content){
        return this.storyService.findContent(content).toString();
    }
}
